#include "fyp/render/ScreenQuad.h"

//------------------------------------------------------------------------------
// additional header includes
#include "fyp/render/Renderer.h"
#include <d3d9.h>

//------------------------------------------------------------------------------
namespace ming
{
namespace fyp
{
namespace render
{
	//--------------------------------------------------------------------------
	TScreenQuad::TScreenQuad(IRenderer *renderer)
	{
		mDevice = static_cast<IDirect3DDevice9*>( renderer->GetApiDevice() );
		mDevice->AddRef();

		mVertices = new TVec3[4];

		mVertices[0] = TVec3(-1, 1, 0) * 1.002f;
		mVertices[1] = TVec3( 1, 1, 0) * 1.002f;
		mVertices[2] = TVec3( 1,-1, 0) * 1.002f;
		mVertices[3] = TVec3(-1,-1, 0) * 1.002f;
	}
	
	//--------------------------------------------------------------------------
	TScreenQuad::~TScreenQuad()
	{
		mDevice->Release();
		mDevice = NULL;

		delete[] mVertices;
		mVertices = NULL;
	}

	//--------------------------------------------------------------------------
	void TScreenQuad::Render()
	{
		mDevice->SetFVF(D3DFVF_XYZ);
		mDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, mVertices, sizeof(TVec3) );
	}

	//--------------------------------------------------------------------------
}
}
}
